//
//  RootViewController.m
//  UI5_HW容器试图控制器
//
//  Created by dllo on 15/11/13.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "TomViewController.h"
#import "ZombieViewController.h"
#import "ColorViewController.h"

@interface RootViewController ()

@property (nonatomic, retain) TomViewController *tomVC;
@property (nonatomic, retain) ZombieViewController *zombieVC;
@property (nonatomic, retain) ColorViewController *colorVC;

@end

@implementation RootViewController

- (void)dealloc
{
    [_tomVC release];
    [_zombieVC release];
    [_colorVC release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    

    
    
    self.tomVC = [[TomViewController alloc] init];
    // 1, 消息通知沿VC传递;
    // 2, 若只添加view, 不添加VC, 可能引起VC被释放的情况
    [self addChildViewController:self.tomVC];
    [self.view addSubview:self.tomVC.view];
    [_tomVC release];
    
    self.zombieVC = [[ZombieViewController alloc] init];
    [self addChildViewController:self.zombieVC ];
    [self.view addSubview:self.zombieVC .view];
    [_zombieVC release];
    
    self.colorVC = [[ColorViewController alloc] init];
    [self addChildViewController:self.colorVC];
    [self.view addSubview:self.colorVC.view];
    [_colorVC release];
    
    [self.view bringSubviewToFront:self.tomVC.view];
    
    UISegmentedControl *segmentC = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Tom", @"Zombie", @"Color", nil]];
    segmentC.selectedSegmentIndex = 0;
//    segmentC.tintColor = [UIColor clearColor];
//    segmentC.backgroundColor = [UIColor blackColor];
    segmentC.center = CGPointMake(180, 300);
    [segmentC addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentC];
    [segmentC release];
    
    
}


- (void)segmentAction:(UISegmentedControl *)sender
{
    if (0 == sender.selectedSegmentIndex) {
        [self.view bringSubviewToFront:self.tomVC.view];
    }
    if (1 == sender.selectedSegmentIndex) {
        [self.view bringSubviewToFront:self.zombieVC.view];
    }
    if (2 == sender.selectedSegmentIndex) {
        [self.view bringSubviewToFront:self.colorVC.view];
    }
    
    // 防止UISegmentedControl被覆盖
    [self.view bringSubviewToFront:sender];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
